<?php

// $Id$

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/_sys/tcms_admin_page_w_fctrl_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/forms/category/category_form_ctrl.class.php');


class Category_Edit_WP extends TCMS_Admin_Page_W_FCtrl_UA {
	public function create_view($name = 'default') {
		$ret = new TCMS_Admin_Page_View($this, $name, 'modules/tangra_cms/pages/_category/');

		return $ret;
	}


	protected function create_form_ctrl() {
		$dbc = $this->get_dbc();
		$tvm = $this->get_tvm();

		$ret = new Category_Form_Ctrl('category', $tvm, $dbc, 'obj_id');



		return $ret;
	}


	protected function on_add_new() {
		$context = $this->get__context();

		if ($context->exists_in_get('parent')) {
			$this->form_ctrl->set_parent($context->get_from_get('parent'));
			$this->form_ctrl->prepare_order($context->get_from_get('parent'));
		}


		if ($context->exists_in_get('parent_parent_category')) {
			$parent_parent_category =  $context->get_from_get('parent_parent_category');
			$this->form_ctrl->set_permanent_external_param('parent_parent_category', $parent_parent_category);
		}

		$this->export('parent_parent_category', $parent_parent_category);
	}


	protected function on_received_id($object_id) {
		$context =$this->get__context();
		if ($context->exists_in_get('parent_parent_category')) {
			$parent_parent_category =  $context->get_from_get('parent_parent_category');
			$this->form_ctrl->set_permanent_external_param('parent_parent_category', $parent_parent_category);
		}

		if ($context->exists_in_get('parent')) {
			$this->form_ctrl->set_parent($context->get_from_get('parent'));
		}

		$this->export('parent_parent_category', $parent_parent_category);
	}


	protected function create_default_redir_view() {
		$redir = new Redirect_Composer_Local($this->get__context(), $this->get_redir_on_success());

		$parent_parent_category = $this->form_ctrl->get_permanent_external_param('parent_parent_category');
		$redir->add_param_pair('parent_category', $parent_parent_category);

		$redir_view = new Just_Headers_View();
		$redir_view->add_http_header($redir->get_location($this->get__context()));

		return $redir_view;
	}
}